package com.ztmmm.module.repo.controller;

import com.ztmmm.common.dto.PageDto;
import com.ztmmm.common.vo.ApiRest;
import com.ztmmm.common.vo.PageResult;
import com.ztmmm.module.repo.entity.Repo;
import com.ztmmm.module.repo.service.IRepoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 题库 前端控制器
 * </p>
 *
 * @author ztm
 * @since 2023-03-20
 */
@RestController
@RequestMapping("/repo")
@Api(description = "题库管理")
@CrossOrigin
public class RepoController {
    @Autowired
    private IRepoService iRepoService;
    @GetMapping("/repo")
    @ApiOperation("查询所有题库（测试用）")
    public List<Repo> selectAll(){
        return iRepoService.selectAll();
    }
    @PostMapping("/page")
    @ApiOperation("分页查询")
    public PageResult<Repo> page(@RequestBody  PageDto<Repo> dto){
       return iRepoService.findPage(dto);
    }
    @PostMapping("save")
    @ApiOperation("添加或修改题库")
    public ApiRest<Repo> save(@RequestBody  Repo repo){
       return iRepoService.add(repo);
    }
    @GetMapping("delete/{repoId}")
    @ApiOperation("通过ID删除题库")
    public ApiRest<Repo> del(@PathVariable String repoId){
        return iRepoService.del(repoId);
    }
    @PostMapping("/deletes")
    @ApiOperation("通过ID批量删除题库")
    public ApiRest<Repo> del(@RequestBody String[] repoId){
        return iRepoService.delAll(repoId);
    }
}
